home *** CD-ROM | disk | FTP | other *** search
/ AOL File Library: 2,801 to 2,900 / aol-file-protocol-4400-2801-to-2900.zip / AOLDLs / C++ Files Library / Direct Blitting in C++ / Blitting.sit / Blitting ƒ / CDirectGWorld.cp < prev    next >
Text File  |  1995-04-15  |  2KB  |  81 lines

  1. // CDirectGWorld.cp, the CDirectGWorld class methods
  2. //
  3. // Copyright ⌐ 1995, Macneil Shonle. All rights reserved.
  4.  
  5. #ifndef __CDIRECTGWORLD__
  6. #include <CDirectGWorld.h>
  7. #endif
  8.  
  9. #ifndef __PIXELTYPES__
  10. #include <PixelTypes.h>
  11. #endif
  12.  
  13. #ifndef __QDOFFSCREEN__
  14. #include <QDOffscreen.h>
  15. #endif
  16.  
  17. CDirectGWorld::CDirectGWorld( Rect &bounds, BitDepth depth, CTabHandle cTable )
  18. {    this->construct( bounds, depth, cTable );
  19. }
  20.  
  21. CDirectGWorld::CDirectGWorld( RowWidth width, ColumnHeight height, BitDepth depth,
  22.                               CTabHandle cTable )
  23. {    Rect bounds = {0, 0, height, width};
  24.     this->construct( bounds, depth, cTable );
  25. }
  26.  
  27. CDirectGWorld::~CDirectGWorld()
  28. {    DestroyQuickRow();
  29.     
  30.     if( mGWorld )
  31.         ::DisposeGWorld( mGWorld );
  32. }
  33.  
  34. GWorldPtr CDirectGWorld::GetMacGWorld()
  35. {    return mGWorld;
  36. }
  37.  
  38. void CDirectGWorld::construct( Rect &bounds, BitDepth depth, CTabHandle cTable )
  39. {    QDErr err = NewCleanGWorld( mGWorld, bounds, depth, cTable );
  40.     
  41.     if( err )
  42.         ::DebugStr( "\pPrimitive Error Checking" );
  43.     
  44.     PixMapHandle thePix = ::GetGWorldPixMap( mGWorld );
  45.     
  46.     mBaseAddress = PixelPtr(::GetPixBaseAddr( thePix ));
  47.     mRowBytes = RowWidth((*thePix)->rowBytes & 0x1FFFL);
  48.     mBounds = bounds;
  49.     mBitDepth = depth;
  50.     mPort = CGrafPtr(mGWorld);
  51.     mGDevice = nil;
  52.     mAddressingMode = ::PixMap32Bit( thePix );
  53.     
  54.     BuildQuickRow();
  55. }
  56.  
  57. QDErr CDirectGWorld::NewCleanGWorld( GWorldPtr &theGWorld, Rect& bounds, BitDepth depth,
  58.                                      CTabHandle cTable )
  59. {    CGrafPtr origPort;
  60.     GDHandle origDev;
  61.     ::GetGWorld( &origPort, &origDev );
  62.     
  63.     QDErr err = ::NewGWorld( &theGWorld, depth, &bounds, cTable, nil, 0 );
  64.     
  65.     if( err == noErr )
  66.     {    ::SetGWorld( theGWorld, nil );
  67.         
  68.         ::LockPixels( ::GetGWorldPixMap( theGWorld ) );                // enable drawing in it
  69.         
  70.             // clean it up
  71.         ::ForeColor( blackColor );
  72.         ::BackColor( whiteColor );
  73.         ::ClipRect( &theGWorld->portRect );
  74.         ::PaintRect( &theGWorld->portRect );
  75.     }
  76.     
  77.     ::SetGWorld( origPort, origDev );
  78.     
  79.     return err;
  80. }
  81.